package com.xiamaliu.fix;

import com.xiamaliu.Member;

public abstract class Handler<T> {

    protected Handler chain;

    public void next(Handler chain) {
        this.chain = chain;
    }

    public abstract void doHandler(Member member);

    public static class Builder<T> {
        private Handler<T> head;
        private Handler<T> tail;

        public Builder<T> addHandler(Handler<T> handler) {
            if (this.head == null) {
                this.head = this.tail = handler;
            } else {
                this.tail.next(handler);
                this.tail = handler;
            }
            return this;
        }

        public Handler<T> build() {
            return this.head;
        }
    }

}
